/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 07 - 17
 * Time: 11:04
 */
import java.util.Scanner;
class TreeNode {
    char val;
    TreeNode left;
    TreeNode right;
    TreeNode(char val) {
        this.val = val;
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()) {
            String s = in.nextLine();
            TreeNode root = creatTree(s);
            inorder(root);
        }
    }
    private static int i = 0;//如果是多个测试用例，则这里会出现问题
    private static TreeNode creatTree(String s) {
        TreeNode root = null;
        if(s.charAt(i) != '#') {
            root = new TreeNode(s.charAt(i));
            i++;
            root.left = creatTree(s);//将创造出来的节点连在root的left和right上
            root.right = creatTree(s);
        }else {
            i++;
        }
        return root;
    }
    private static void inorder(TreeNode root) {
        if(root == null) {
            return;
        }
        inorder(root.left);
        System.out.print(root.val + " ");
        inorder(root.right);
    }
}
